<?php
    //CLIENT SIDE PROGRAM

    define('ABSOLUTE_SERVER_DOCUMENT_ROOT',$_SERVER['DOCUMENT_ROOT'].'/');

    require_once('product_link.inc');
    require_once(ABSOLUTE_SERVER_DOCUMENT_ROOT.'OpenDB.inc');
    require_once(ABSOLUTE_SERVER_DOCUMENT_ROOT.'functs.inc');
    include ABSOLUTE_SERVER_DOCUMENT_ROOT.'color_style_shop.php';
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>

<head>

    <title>OWS</title>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1250" />
    <style  type="text/css"><!--
                table{
                    border-bottom-color: black;
                    border-top-color: black;
                    border-left-color: black;
                    border-right-color: black;
                    border-collapse: collapse;
                    font-size: 12px;
                }
                form {margin-top:0pt; margin-bottom:0px;}
                img {margin-top:0pt; margin-bottom:0px;}
                body{
                    margin-left:10pt;
                    margin-right:0pt;
                    margin-top:0pt;
                    margin-bottom:0pt;
                    font-family:  Verdana;
                    font-size: 12px;
                }
                input {
                    border: 1px solid black;
                    cursor: hand;
                    width: 200px;
                    background-color: white;
                    font-size: 10px;
                    margin-left: 0px;
                    padding-left: 0px;
                    list-style-type: none;
                    font-family:  Verdana;
                }
                textarea {
                 	font-size: 10px;
					font-family: verdana;
					width: 400px;
					height: 150px;
					white-space: wrap; 
                }
                h3 {
					font-size:		14px;
					font-family:	Verdana;
					text-align:		center;
				}

        --></style>

</head>

<?php

	print"<body bgcolor=\"".BACKGROUND_COLOR."\">";

	if (!OpenDB()){echo "Chyba Databazy-na odstraneni chyby pracujeme."; break;}
	
	print "<h3>Odosla� odkaz na produkt na e-mail</h3>";
	

	//----------------------------------------------------------------------------
	//Zistenie prihlaseneho uzivatela z cookie
    if(isset($_COOKIE['ker_username']) and isset($_COOKIE['keramika_user'])){
        $UserNameCookie = $_COOKIE['ker_username'];
        DecodeCookie($UserNameCookie,$U_Name,$U_Surname);
        $UserNameCookie = $_COOKIE['keramika_user'];
        DecodeCookie($UserNameCookie,$User_ID,$U_Passwd);
        @$SQL_result = mysql_query("SELECT U_Email FROM users WHERE ID=".$User_ID);
        if ($SQL_result){
            $sql_array = mysql_fetch_object($SQL_result);
            $Ch_Email=$sql_array->U_Email;
        }
    }
    else{
          $U_Name="";
          $U_Surname="";
    }
	//----------------------------------------------------------------------------


	//----------------------------------------------------------------------------
	//nacitanie dat z DB ak nejde o odosielanie mailu
	if($_REQUEST['Address']!=""){
		if (!OpenDB()){echo "Chyba Databazy-na odstraneni chyby pracujeme."; break;}
		$sql="select * from products where ID=".$_REQUEST['Product_ID'];
        $sql_array = mysql_fetch_object($sql);
        
        $Product_Name = $sql_array->Product_Name;
        
		mysql_close(); 
	}		
	//----------------------------------------------------------------------------


	//----------------------------------------------------------------------------
	//odoslanie e-mailu
	if($_REQUEST['Address']!=""){
	  	$Text = $_REQUEST['Text']."\n\n\n S pozdravom ".$_REQUEST['Name']." ".$_REQUEST['Surname']." ".$_REQUEST['Email_Sender'];
		Send_Mail($Address,$_REQUEST['Caption'],$Text);
		
		print "Email v poriadku odoslan�!";
		
	}
	//----------------------------------------------------------------------------
	

	//----------------------------------------------------------------------------
	//formular pre zadanie udajov
	if ($_REQUEST['Address']==""){
		$Text=	"Dobry Den. \n\nZasielam V�m odkaz na produkt, nach�dzaj�ci sa v internetovom obchode "
				.$_SERVER["HTTP_HOST"]
				."\n\nKliknite na nasleduj�ci odkaz, alebo ho skop�rujte do svojho WWW prehliada�a:\n\n"
				.Product_Link($_REQUEST['ProductID']);
		print "
			<form action=\"product_link.php\" target=\"product_link_mail\" method=\"post\">
			<table>
				<tr>
					<td>
						E-mail prij�mate�a:
					<td>
					<td>
						<input type=\"text\" name=\"Address\" value=\"\" /> (Viacer� adresy odde�te �iarkami \",\")
					</td>
				</tr>
				<tr>
					<td colspan=\"2\">
						<b>Odosielate�:</b>
					</td>
				</tr>
				<tr>
					<td>
						E-mail odosielate�a:
					<td>
					<td>
						<input type=\"text\" name=\"Email_Sender\" value=\"$Ch_Email\" />
					</td>
				</tr>
				<tr>
					<td>
						Meno:
					<td>
					<td>
						<input type=\"text\" name=\"Name\" value=\"$U_Name\" />
					</td>
				</tr>
				<tr>
					<td>
						Priezvisko:
					<td>
					<td>
						<input type=\"text\" name=\"Surname\" value=\"$U_Surname\" />
					</td>
				</tr>
				<tr>
					<td>
						Predmet:
					<td>
					<td>
						<input type=\"text\" name=\"Caption\" value=\"Posielam odkaz na produkt\" />
					</td>
				</tr>
				<tr>
					<td>
						Text:
					<td>
					<td>
						<textarea name=\"Text\">$Text</textarea>
					</td>
				</tr>
				<tr>
					<td colspan=\"2\">
						<input type=\"submit\" value=\"Odosla� e-mail\" style=\"width:150px; background-color: transparent;\" 
							onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold'\"
	        				onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal'\" />
					</td>
				</tr>
			</table>
			</form>
		";
	}
	//----------------------------------------------------------------------------
	
	//tlacitko "ZAVRIET"
    print "	<br />
    		<br />
    		<center>
				<input type=\"button\" value=\"Zavrie�\"
	                style=\"width :183px; height:15px; background-color: ".BUTTON_ON_OUT.";\"
	    			onClick=\"javascript:window.close()\"
	        		onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold'\"
	        		onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal'\" />
			</center>
	";
?>
</body>
</html>
